package org.wheres2.location.customview;

import org.wheres2.R;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

public class CompassView extends View {
	private Paint paint;
	private int positionViewW;
	private int positionViewH;
	private int azimuth=0;
	private Bitmap coordinate;
	private int coordinateW;
	private int coordinateH;
	
	public CompassView(Context context, AttributeSet attrs){
		super(context, attrs);
		
		paint = new Paint();
		Bitmap bmp;
		bmp= BitmapFactory.decodeResource(context.getResources(), R.drawable.coordinate);
		coordinate= Bitmap.createScaledBitmap(bmp, bmp.getWidth()/2, bmp.getHeight()/2, false);
		
	}
	
	@Override
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
		
		coordinateW=coordinate.getWidth();
		coordinateH=coordinate.getHeight();
		positionViewW = this.getWidth();
		positionViewH = this.getHeight();
		canvas.rotate(azimuth, positionViewW/2,positionViewH/2 );
		
		
		canvas.drawBitmap(coordinate, (positionViewW-coordinateW)/2, (positionViewH-coordinateH)/2, paint);
		

	}
	
	/**
	 * Setta il valore della variabile azimuth
	 * 
	 * @param azimuth
	 * 
	 */
	public void setAzimuth(int azimuth) {
		this.azimuth = -1*azimuth;
	}
}
